--- interact_link: content/08/08/plotly8-8.ipynb kernel_name: python3 kernel_path: content/08/08 has_widgets: false title: |- Distribution Plots pagenum: 21 prev_page: url: /08/07/plotly8-7.html next_page: url: /08/09/plotly8-9.html suffix: .ipynb search: distribution id plot want values plots plotlydistributionplots ly python distplot good center spread might investigate extreme study pattern data plotlydistributionplotsbasic basic plotlydistributionplotsmulti multi plotlydistributionplotsline line plotlydistributionplotsbox box comment: "***PROGRAMMATICALLY GENERATED, DO NOT EDIT. SEE ORIGINAL FILES IN /content***" ---
Distribution Plots

Distribution Plots

Distribution plots are good to use:

  • When you want to know the center and the spread about your values.
  • When you might want to investigate extreme values
  • When you want to study the distribution or pattern of the data values.

Basic Distribution Plot

import plotly.figure_factory as ff #Take note thet we are using figure_factory instead of graphic objects
import plotly.graph_objects as go
import numpy as np
from plotly.offline import init_notebook_mode, plot
from IPython.core.display import display, HTML
init_notebook_mode(connected=True)

x = np.random.randn(1000) #create random dataset
hist_data = [x]
group_labels = ['distplot'] 

fig = ff.create_distplot(hist_data, group_labels)

plot(fig, filename = 'figure8-8-1.html')
display(HTML('figure8-8-1.html'))

Multi-Distribution Plot

# Add histogram data
x1 = np.random.randn(200)-2
x2 = np.random.randn(200)
x3 = np.random.randn(200)+2
x4 = np.random.randn(200)+4

# Group data together
hist_data = [x1, x2, x3, x4]

group_labels = ['Group 1', 'Group 2', 'Group 3', 'Group 4']

fig = ff.create_distplot(hist_data, group_labels, bin_size=[.1, .25, .5, 1]) #Note that we are setting bins sizes for each group

plot(fig, filename = 'figure8-8-2.html')
display(HTML('figure8-8-2.html'))

Line Distribution Plot

x1 = np.random.randn(200) - 1
x2 = np.random.randn(200)
x3 = np.random.randn(200) + 1

hist_data = [x1, x2, x3]

group_labels = ['Group 1', 'Group 2', 'Group 3']
colors = ['#333F44', '#37AA9C', '#94F3E4']

fig = ff.create_distplot(hist_data, group_labels, show_hist=False, #set show_hist to false to have only the line
                         curve_type='normal', colors=colors) #Curve type normal makes a normal distribution

# Add title
fig.update_layout(title_text='Curve and Rug Plot')

plot(fig, filename = 'figure8-8-3.html')
display(HTML('figure8-8-3.html'))

Box Distribution Plot

#Same as above but with bars

# Create distplot with curve_type set to 'normal'
fig = ff.create_distplot(hist_data, group_labels, colors=colors, bin_size=.25, curve_type='normal',
                         show_curve=False)

# Add title
fig.update_layout(title_text='Hist and Rug Plot')

plot(fig, filename = 'figure8-8-4.html')
display(HTML('figure8-8-4.html'))